Applications executed on a computer may be stored locally, such as on a disk or other secondary storage device attached to the computer. Alternatively, they may be stored on a remote server. In the latter case, the binary code of the application is transmitted over the network from the server machine, on which the code is stored, to the client machine, which executes the code. The binary code for the given application may be transmitted from the server to the client every time the application is to be executed, or it may be transmitted once and saved locally for subsequent executions.
The network is usually the bottleneck in terms of speed in the server-network-client chain. If the client machine connects to the Internet using a modem and a telephone line, or a slow wireless network, then delays in downloading time are plentiful. Because of this bottleneck, most of the time it takes to download an application is taken up by network delays.
In computer science, a virtual machine is software that acts as an interface between compiler binary code and the microprocessor (or other hardware platform) that actually performs the machine's instructions. This allows software written for a particular platform to be run on any platform compatible with the virtual machine, without the need for code to be rewritten or recompiled by the programmer for each separate platform. Java Virtual Machine™ (Java VM) from Sun Microsystems of Palo Alto, Calif. is an example of a virtual Machine. Once a Java VM has been provided for a platform, any Java program can run on that platform.
If an application executed by a virtual machine is written in an object-oriented language, the executable code of the application typically takes the form of a number of classes that the virtual machine loads in memory and executes. Classes are normally loaded by the VM individually and lazily in that each class is loaded only at the time when the executed application needs it, which may be much later than when the application starts. Again, the Java language and its implementation are an example of this. The Java implementation defines applets, which are applications whose binary code is downloaded by the client JVM from the server before each invocation. Alternatively, it is possible to store a Java application on a server, then download it onto a client machine (manually or using a special installation program) and subsequently execute this local copy of the application as many times as needed.
A class in an object-oriented language can be defined in multiple ways, but for the purposes of this application a class is defined as a collection of methods. A method, in turn, is a chunk of executable code that can be called (or executed) by other methods from its own class or other classes.
Applications executed by a virtual machine often make the virtual machine load many classes, each containing numerous methods. This is typically due to the fact that library classes are used extensively. A library is a (typically large) collection of classes that implement some common functionality. The so-called core classes defined in the Java language implementation is an example of a class library. While libraries provide convenience for the programmer, allowing them to utilize readily available classes instead of writing the necessary code themselves, they may also waste memory space and processor time. This is due to the fact that only a fraction of methods contained in a typical library class are actually used, i.e., called directly or indirectly by the application code. Nevertheless, the virtual machine dynamically loads into memory a complete representation of each class, even if only one method of this class is actually used. As a result, a significant amount of main memory is wasted at run time. Additionally, virtual machines typically manage memory automatically by performing garbage collection, during which objects in memory are moved around. Thus, the more wasted space utilized in memory, the more time needed to manage it.
FIG. 1 is a diagram illustrating an example of how a virtual machine is typically loaded with classes from the remote server. Class C 100 has four methods, M1 102, M2 104, M3 106, and M4 108. Class C 100 is contained on disk 110 on the server machine. Upon request, the server transmits all four methods M1 112, M2 114, M3 116, and M4 118 to the virtual machine on the client. However, perhaps only M2 and M4 are referenced in the application code (methods which are referenced in the application code are indicated as such by shading). Therefore, this solution causes the virtual machine to unnecessarily download and load M1 and M3, which slows execution and wastes bandwidth and memory space.
What is needed is a solution that reduces the size and speed drawbacks of loading complete classes into virtual machines.